package com.vilen.cms.web;

import com.vilen.cms.auth.AuthUtil;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import java.util.Map;
import java.util.Set;

/**
 * Created by vilen on 2017/2/15.
 */
public class InitServlet extends HttpServlet{

    private static WebApplicationContext webApplicationContext;

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        // 初始化 spring 工厂
        webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        //初始化权限信息
        Map<String, Set<String>> auths = AuthUtil.initAuth("com.vilen.cms.controller");
        this.getServletContext().setAttribute("allAuths", auths);
        System.out.println("---------------系统初始化---------");
        System.out.println("---------------系统初始化权限---------"+auths);
    }

    public static WebApplicationContext getWebApplicationContext() {
        return webApplicationContext;
    }
}
